package com.seventh.blecore;

import android.app.Activity;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.seventh.blecore.callback.NotifyCallback;
import com.seventh.blecore.callback.ResponseCallback;
import com.seventh.blecore.callback.SearchCallback;
import com.seventh.blecore.client.BluetoothClientProxy;

/**
 * @author chengxin
 * create at 2021/4/19
 * description:Unity通用接口类
 */
public interface IUnityCallBle {
    /**
     * 是否显示调试信息
     *
     * @param debug true 显示debug信息
     */
    void setDebug(boolean debug);

    /**
     * 设置BluetoothClient 请求回调函数的线程，默认不是主线程
     *
     * @param postUi if true is android main Thread[main,5,main],
     *               else is Thread[BluetoothClientImpl,5,main],false可以防止消息过多时主线程堵塞
     * @see BluetoothClientProxy#setPostUi(boolean)
     */
    void setPostUi(boolean postUi);

    /**
     * 设置当前Android测试调用的页面，用于弹出窗口之类使用
     */
    void setAndroidTestActivity(@NonNull Activity activity);

    /**
     * 第一步
     * 搜索扫描蓝牙设备
     *
     * @param filterName        过滤名称
     * @param scanTime          扫描时间
     * @param showDevicesDialog 是否显示设备窗口
     */
    void searchByName(@Nullable String filterName, int scanTime, boolean showDevicesDialog, @NonNull SearchCallback callback);

    /**
     * 第一步
     * 搜索扫描蓝牙设备
     *
     * @param filterAddresses   过滤 mac address,"address1,address2"(address地址用","分割)
     * @param scanTime          扫描时间
     * @param showDevicesDialog 是否显示设备窗口
     */
    void searchByAddresses(@Nullable String filterAddresses, int scanTime, boolean showDevicesDialog, @NonNull SearchCallback callback);

    void stopSearch();

    /**
     * 连接蓝牙设备
     */
    void connect(@NonNull String mac, @NonNull ResponseCallback callback);

    /**
     * 断开连接
     */
    void disconnect(@NonNull String mac);

    void notify(@NonNull String mac, @NonNull String service, @NonNull String character, @NonNull NotifyCallback callback);

    /**
     * @param noResponse {@link BluetoothGattCharacteristic#PROPERTY_WRITE}
     *                   or {@link BluetoothGattCharacteristic#PROPERTY_WRITE_NO_RESPONSE}
     */
    void write(boolean noResponse, @NonNull String mac, @NonNull String service, @NonNull String character, @NonNull byte[] data, @NonNull ResponseCallback callback);

    /**
     * 获取配对状态
     * Get the bond state of the remote device.
     * <p>Possible values for the bond state are:
     * {@link BluetoothDevice#BOND_NONE},
     * {@link BluetoothDevice#BOND_BONDING},
     * {@link BluetoothDevice#BOND_BONDED}.
     *
     * @return the bond state
     */
    int getBondState(@NonNull String mac);

    /**
     * 获取连接状态
     */
    int getConnectStatus(@NonNull String mac);

    boolean isDeviceConnected(@NonNull String mac);
}
